package com.atguigu.sparkcore.day03.action

import org.apache.spark.{SparkConf, SparkContext}

/**
 * Author atguigu
 * Date 2020/10/30 9:12
 */
object CountByKey {
    def main(args: Array[String]): Unit = {
        val conf: SparkConf = new SparkConf().setAppName("CountByKey").setMaster("local[2]")
        val sc: SparkContext = new SparkContext(conf)
        val list1 = List(30, 50, 70, 30, 50, 70, 60, 10, 20).map((_, 100))
        val rdd1 = sc.parallelize(list1, 2)
        //        rdd1.reduceByKey(_ + _).collect().foreach(print)
        val wordCount: collection.Map[Int, Long] = rdd1.countByKey()
        println(wordCount)
        sc.stop()
        
    }
}
/*

reduceByKey和countByKey的区别
1. reduceByKey 是转换算子  countByKey 行动算子
2. reduceByKey 对value的做聚合
3. countByKey 对key做计数

 */